package ae.pcfc.etks.online.itworx.ehs.web.common.exception.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ae.pcfc.etks.online.itworx.ehs.web.common.exception.BaseException;
import ae.pcfc.etks.online.itworx.ehs.web.common.exception.handler.BaseExceptionHandler;
import ae.pcfc.etks.online.itworx.ehs.web.messaging.JmsMessageProducer;

/**
 * concrete class that handles the logic of handling the exception
 * 
 * @author Ahmed.Mostafa
 */
public class EHSExceptionHandler implements BaseExceptionHandler {

	private JmsMessageProducer producer;
	private static Logger log = LoggerFactory.getLogger(EHSExceptionHandler.class);

	public void setProducer(JmsMessageProducer producer) {
		this.producer = producer;
	}

	/**
	 * handles EHS exceptions
	 */
	public void handleException(BaseException e) {
		if (null!= e.getErrorRollbackBean()) {
			producer.generateRollbackMessage(e
					.getErrorRollbackBean());
			log.error("EHSExceptionHandler.handleException() - exception occurred and has rolled back",e);
		}
		if (e instanceof Exception) {
			// TODO write the logging code here
			log.error("EHSExceptionHandler.handleException() - exception occurred",e);
		}
	}
}